'use strict';
const Client = require('./client');
const User = require('./user');
module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;

  const AccessToken = app.model.define('authorization_code', {
    id: { type: STRING, primaryKey: true, field: 'authorization_code'},
    expiresAt: DATE,
    redirectUri: STRING,
    scope: STRING,
    clientId: {
        type: STRING,
        references: {
            // This is a reference to another model
            model: Client,
       
            // This is the column name of the referenced model
            key: 'id',
       
            // This declares when to check the foreign key constraint. PostgreSQL only.
            //deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE
          }
    },
    userId: {
      type: INTEGER,
      references: {
          // This is a reference to another model
          model: User,
     
          // This is the column name of the referenced model
          key: 'id',
     
          // This declares when to check the foreign key constraint. PostgreSQL only.
          //deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE
        }
    },
    createdAt: DATE,
    updatedAt: DATE,
  });

  return AccessToken;
};